package com.ithinks.flow.common.utils.protocol.netty.embedded;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.Test;

import static org.junit.Assert.*;
/**
 * @Description
 * @ClassName AbsIintegerEncoderTest
 * @Author MR.LI
 * @date 2020.12.09 16:55
 */
public class AbsIintegerEncoderTest {
    @Test
    public void TestEncoded(){
        ByteBuf buf = Unpooled.buffer();
        for(int i=0;i<10;i++){
            buf.writeInt(i*-1);
        }

        EmbeddedChannel channel = new EmbeddedChannel(new AbsIntegerEncoder());
        assertTrue(channel.writeOutbound(buf));
        assertTrue(channel.finish());
        for(int i = 1; i<10; i++){
            assertEquals(java.util.Optional.of(i),channel.readOutbound());
        }
        assertNull(channel.readOutbound());
    }
}
